home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / rpclib / svc_raw.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  5KB  |  173 lines

  1. /*
  2.  * $Id: svc_raw.c,v 1.3 1994/02/25 00:21:41 jraja Exp $
  3.  *
  4.  * $Log: svc_raw.c,v $
  5.  * Revision 1.3  1994/02/25  00:21:41  jraja
  6.  * Changed malloc, calloc and free to mem_alloc, mem_calloc and mem_free,
  7.  * respectively.
  8.  *
  9.  * Revision 1.2  1993/11/10  02:49:43  jraja
  10.  * ANSI prototypes. Added include sys/param.h.
  11.  *
  12.  */
  13. /* @(#)svc_raw.c    2.1 88/07/29 4.0 RPCSRC */
  14. /*
  15.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  16.  * unrestricted use provided that this legend is included on all tape
  17.  * media and as a part of the software program in whole or part.  Users
  18.  * may copy or modify Sun RPC without charge, but are not authorized
  19.  * to license or distribute it to anyone else except as part of a product or
  20.  * program developed by the user.
  21.  * 
  22.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  23.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  24.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  25.  * 
  26.  * Sun RPC is provided with no support and without any obligation on the
  27.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  28.  * modification or enhancement.
  29.  * 
  30.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  32.  * OR ANY PART THEREOF.
  33.  * 
  34.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  35.  * or profits or other special, indirect and consequential damages, even if
  36.  * Sun has been advised of the possibility of such damages.
  37.  * 
  38.  * Sun Microsystems, Inc.
  39.  * 2550 Garcia Avenue
  40.  * Mountain View, California  94043
  41.  */
  42. #if !defined(lint) && defined(SCCSIDS)
  43. static char sccsid[] = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";
  44. #endif
  45.  
  46. /*
  47.  * svc_raw.c,   This a toy for simple testing and timing.
  48.  * Interface to create an rpc client and server in the same UNIX process.
  49.  * This lets us similate rpc and get rpc (round trip) overhead, without
  50.  * any interference from the kernal.
  51.  *
  52.  * Copyright (C) 1984, Sun Microsystems, Inc.
  53.  */
  54.  
  55. #include <sys/param.h>
  56. #include <rpc/rpc.h>
  57.  
  58.  
  59. /*
  60.  * This is the "network" that we will be moving data over
  61.  */
  62. static struct svcraw_private {
  63.     char    _raw_buf[UDPMSGSIZE];
  64.     SVCXPRT    server;
  65.     XDR    xdr_stream;
  66.     char    verf_body[MAX_AUTH_BYTES];
  67. } *svcraw_private;
  68.  
  69. static bool_t        svcraw_recv(SVCXPRT *, struct rpc_msg *);
  70. static enum xprt_stat     svcraw_stat(SVCXPRT *);
  71. static bool_t        svcraw_getargs(SVCXPRT *xprt, xdrproc_t xargs, 
  72.                        void * argsp);
  73. static bool_t        svcraw_reply(SVCXPRT *xprt,
  74.                      struct rpc_msg *msg);
  75. static bool_t        svcraw_freeargs(SVCXPRT *xprt, xdrproc_t xargs, 
  76.                         void * argsp);
  77. static void        svcraw_destroy(SVCXPRT *xprt);
  78.  
  79. static struct xp_ops server_ops = {
  80.     svcraw_recv,
  81.     svcraw_stat,
  82.     svcraw_getargs,
  83.     svcraw_reply,
  84.     svcraw_freeargs,
  85.     svcraw_destroy
  86. };
  87.  
  88. SVCXPRT *
  89. svcraw_create(void)
  90. {
  91.     register struct svcraw_private *srp = svcraw_private;
  92.  
  93.     if (srp == 0) {
  94.         srp = (struct svcraw_private *)mem_calloc(1, sizeof (*srp));
  95.         if (srp == 0)
  96.             return (0);
  97.     }
  98.     srp->server.xp_sock = 0;
  99.     srp->server.xp_port = 0;
  100.     srp->server.xp_ops = &server_ops;
  101.     srp->server.xp_verf.oa_base = srp->verf_body;
  102.     xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
  103.     return (&srp->server);
  104. }
  105.  
  106. static enum xprt_stat
  107. svcraw_stat(SVCXPRT *xprt)
  108. {
  109.  
  110.     return (XPRT_IDLE);
  111. }
  112.  
  113. static bool_t
  114. svcraw_recv(SVCXPRT *xprt, struct rpc_msg *msg)
  115. {
  116.     register struct svcraw_private *srp = svcraw_private;
  117.     register XDR *xdrs;
  118.  
  119.     if (srp == 0)
  120.         return (0);
  121.     xdrs = &srp->xdr_stream;
  122.     xdrs->x_op = XDR_DECODE;
  123.     XDR_SETPOS(xdrs, 0);
  124.     if (! xdr_callmsg(xdrs, msg))
  125.            return (FALSE);
  126.     return (TRUE);
  127. }
  128.  
  129. static bool_t
  130. svcraw_reply(SVCXPRT *xprt, struct rpc_msg *msg)
  131. {
  132.     register struct svcraw_private *srp = svcraw_private;
  133.     register XDR *xdrs;
  134.  
  135.     if (srp == 0)
  136.         return (FALSE);
  137.     xdrs = &srp->xdr_stream;
  138.     xdrs->x_op = XDR_ENCODE;
  139.     XDR_SETPOS(xdrs, 0);
  140.     if (! xdr_replymsg(xdrs, msg))
  141.            return (FALSE);
  142.     (void)XDR_GETPOS(xdrs);  /* called just for overhead */
  143.     return (TRUE);
  144. }
  145.  
  146. static bool_t
  147. svcraw_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, void * args_ptr)
  148. {
  149.     register struct svcraw_private *srp = svcraw_private;
  150.  
  151.     if (srp == 0)
  152.         return (FALSE);
  153.     return ((*xdr_args)(&srp->xdr_stream, args_ptr));
  154. }
  155.  
  156. static bool_t
  157. svcraw_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, void * args_ptr)
  158.     register struct svcraw_private *srp = svcraw_private;
  159.     register XDR *xdrs;
  160.  
  161.     if (srp == 0)
  162.         return (FALSE);
  163.     xdrs = &srp->xdr_stream;
  164.     xdrs->x_op = XDR_FREE;
  165.     return ((*xdr_args)(xdrs, args_ptr));
  166.  
  167. static void
  168. svcraw_destroy(SVCXPRT *xprt)
  169. {
  170. }
  171.